home *** CD-ROM | disk | FTP | other *** search
/ IRIS Performer 2.2 Friends Demo / SGI IRIS Performer 2.2 Friends Demo.iso / friends / devices / BGSystems / bg / check_rev.c next >
C/C++ Source or Header  |  1997-10-31  |  5KB  |  211 lines

  1. /*
  2.  * Copyright 1994   BG Systems, Inc.
  3.  * check_rev.c
  4.  *
  5.  * routine that checks the EPROM revision
  6.  *
  7.  * Author         Date       Comments
  8.  * John Green     21-Oct-94  Author
  9.  * John Green     01-Feb-95  Rev 3.0 release version.
  10.  * John Green     09-Feb-95  Fixed input checking.
  11.  */
  12.  
  13. static char SccsId[] = "@(#)check_rev.c    1.4 10 Feb 1995";
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <unistd.h>
  18. #include <string.h>
  19.  
  20. #include "lv3.h"
  21.  
  22. static char Cpy[] = "Copyright (c), BG Systems";
  23.  
  24. int parse_year(char *);
  25. void no_answer(void);
  26.  
  27. int check_rev(bglv *bgp)
  28. {
  29.    int st;
  30.    int chars_read = 0;
  31.    char str[64];
  32.  
  33. /*
  34.  *  Send a "T" and see if the Box responds
  35.  */
  36.    st = write(bgp->sp_fd, "T", 2);
  37.    sginap(100); 
  38.    chars_read = read(bgp->sp_fd, str, 44);
  39.  
  40. /*
  41.  *  If chars_read <= 0, looks like we have a Rev 1.x EPROM
  42.  */
  43.    if (chars_read <= 0)
  44.    {
  45.       no_answer();
  46.       return(-1);
  47.    }
  48.    else
  49.    {
  50. /*
  51.  *  Check the string length
  52.  */
  53.       if ( chars_read != 44 )
  54.       {
  55.          printf("Unexpected characters:  %d  %s\n", chars_read, str);
  56.          return(-1);
  57.       }
  58.       else
  59.       {
  60. /*
  61.  *  Check that it is the Copyright string
  62.  */
  63.          if ( strncmp(str, Cpy, strlen(Cpy)) != 0 )
  64.          {
  65.             printf("Unexpected characters:  %d  %s\n", chars_read, str);
  66.             return(-1);
  67.          }
  68.          else
  69.          {
  70. /*
  71.  *  If we go this far, we should have the right string 
  72.  */
  73.             bgp->Rev.year  = parse_year(str);
  74.             bgp->Rev.major = str[38]-48;
  75.             bgp->Rev.minor = str[40]-48;
  76.             bgp->Rev.bug   = str[41]-48;
  77.             bgp->Rev.alpha = str[42];
  78.             printf("%s %d  Revision %d.%d%d%c\n", Cpy, bgp->Rev.year,
  79.                       bgp->Rev.major,  bgp->Rev.minor,
  80.                       bgp->Rev.bug, bgp->Rev.alpha );
  81.          }
  82.       } 
  83.    }
  84.  
  85.    return (bgp->Rev.major);
  86. }
  87.  
  88. int parse_year(char *s)
  89. {
  90.    int i = 0;
  91.    char yr[12];
  92.  
  93.    while ( *s != '1' )
  94.       *s++;
  95.    yr[i] = *s;
  96.    while ( *s != ' ' && *s != ',' )
  97.       yr[i++] = *s++;
  98.    yr[i] = '\0';
  99.    return(atoi(yr));
  100. }
  101.  
  102. int check_setup(bglv *bgp)
  103. {
  104.    int i;
  105.    int st = 0;
  106.  
  107. /*
  108.  *  This routine checks the EPROM revision against the
  109.  *  requested setup, and attempts to identify inconsistencies !
  110.  */
  111.  
  112.    if ( bgp->Rev.major == 2 )
  113.    {
  114.       if ( bgp->analog_out != 0x0 )
  115.       {
  116.          printf("  Analog outputs not supported by LV816\n");
  117.          st = -1;
  118.       }
  119.       if ( bgp->dig_out != 0x0 )
  120.       {
  121.          printf("  Digital outputs not supported by LV816\n");
  122.          st = -2;
  123.       }
  124.       if ( bgp->dig_in & 0x40 )
  125.       {
  126.          printf("  Digital inputs 19-24 not supported by LV816\n");
  127.          st = -3;
  128.       }
  129.    }
  130.    else if ( bgp->Rev.major == 3 )
  131.    {
  132.       switch(bgp->Rev.alpha)
  133.       {
  134.        case 'e':
  135.          printf("LV824-E\n");
  136.          if ( bgp->analog_out != 0x0 )
  137.          {
  138.             printf("  Analog outputs not supported\n");
  139.             st = -1;
  140.          }
  141.          if ( bgp->dig_out != 0x0 )
  142.          {
  143.             printf("  Digital outputs not supported\n");
  144.             st = -2;
  145.          }
  146.          break;
  147.        case 'f':
  148.          printf("LV824-F\n");
  149.          if ( bgp->analog_out != 0x0 )
  150.          {
  151.             printf("  Analog outputs not supported\n");
  152.             st = -2;
  153.          }
  154.          break;
  155.        case 'g':
  156.          printf("LV824-G\n");
  157.          break;
  158.        default:
  159.          st = -3;
  160.          printf("Not an LV824 board\n");
  161.          break;
  162.       }
  163.       if ( st < 0 )
  164.          return(st);
  165. /*
  166.  *  Check also for conflict in the digital channels
  167.  */
  168.  
  169.       if ( bgp->dig_in && bgp->dig_out )
  170.       {
  171.          for ( i = 0; i < 3; i++ )
  172.          {
  173.             if ( ( (bgp->dig_in >> i) &0x1 ) 
  174.                  && ( (bgp->dig_out >> i) &0x1 ) )
  175.             {
  176.  
  177. printf("Invalid set-up requested.\n");
  178. printf("  Digital input group %d AND output group %d selected\n",                        i+1, i+1);
  179.  
  180. printf("\n\n  Digital channels can be set in groups of 8 as\n");
  181. printf("  either inputs or outputs.\n");
  182. printf("  Of course you can (for example) set the bottom 8\n");
  183. printf("  to inputs DIC1 and the top 16 to outputs DOC2 | DOC3\n");
  184.  
  185.                st = -5;
  186.                return(st);
  187.             }
  188.          }
  189.       }
  190.    }
  191.    return(st);
  192. }
  193.  
  194. void no_answer()
  195. {
  196.    printf("\nWriting a 'T' to the Box produced no answer.  \n");
  197.    printf("\n");
  198.    printf("The expected string was not returned from the BG box.\n");
  199.    printf("Here are some possible problems:\n");
  200.    printf("   1. Check power to Box\n");
  201.    printf("   2. Check the serial cable\n");
  202.    printf("   3. Check the environment variable FBPORT\n");
  203.    printf("      - does it match the connected serial port ?\n");
  204.    printf("   4. Is the serial port configured as a terminal ? \n");
  205.    printf("      - if so use \"System Manager\" to disconnect the port\n");
  206.    printf("   5. You have an old FlyBox (serial no. less than 60) \n");
  207.    printf("         which has a revision 1.0 EPROM.  Call BG Systems.\n");
  208.  
  209.    printf("\n\n");
  210. }
  211.